package com.example.xiaomi.controller;
import com.example.xiaomi.entity.AdminInfo;
import com.example.xiaomi.service.AdminService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("admin")
@CrossOrigin
public class AdminController {
    @Autowired
    private AdminService service;
    @GetMapping("/pages")
    public PageInfo<AdminInfo> getPagesAdmin(Integer pageNum, Integer pageSize, String adminname){
        PageInfo<AdminInfo> pageInfo = service.findAdminPages(pageNum,pageSize,adminname);
        return pageInfo;
    }

    @GetMapping("list")
    public List<AdminInfo> findalladmin(String adminname){

        return service.findAllAdmin(adminname);
    }

    @PostMapping("update")
    public Integer updateAdmin(@RequestBody AdminInfo adminInfo){
        return service.updateAdmin(adminInfo);}

    /**
     * 根据主键编号提取管理员信息： http://localhost:8080/admin/get/#{aid}    get请求
     * @return
     */
    @GetMapping("/get/{aid}")
    public AdminInfo getAdminBYID(@PathVariable("aid") Integer adminid){
        AdminInfo info =service.findAdminBYID(adminid);
        return info;
    }

    /**
     * 根据主键编号删除管理员信息：http://localhost:8080/admin/del/#{aid}
     * @param adminid
     * @return
     */
    @GetMapping("/del/{aid}")
    public Integer deleteBYID(@PathVariable("aid") Integer adminid){

        return service.deleteBYID(adminid);
    }
}
